# -*- coding: utf-8 -*-
# @Time    : 2022/5/11 15:33
# @Author  : ShaHeTop-Almighty-ares
# @Email   : yang6333yyx@126.com
# @File    : config.py
# @Software: PyCharm

import os
import configparser

project_name = 'ExileAioServer'


def get_config():
    """获取配置文件"""
    conf = configparser.ConfigParser()
    AIO_SERVER_ENV = os.environ.get('AIO_SERVER_ENV')
    current_path = os.getcwd()
    config_path = current_path.split(project_name)[0] + project_name + '/config'
    default_env = {
        'config_path': config_path + '/dev.ini',
        'msg': '本地配置文件:{}'.format(config_path + '/dev.ini'),
    }
    env_path_dict = {
        'default': default_env,
        'uat': {
            'config_path': config_path + '/uat.ini',
            'msg': f'uat配置文件:{config_path}/uat.ini'
        },

        'production': {
            'config_path': config_path + '/prod.ini',
            'msg': f'prod配置文件:{config_path}/prod.ini'
        },
    }

    env_obj = env_path_dict.get(AIO_SERVER_ENV, default_env)
    msg = env_obj.get('msg')
    config_path = env_obj.get('config_path')
    print(config_path)
    print(msg)
    conf.read(config_path)

    # return conf

    conf_dict = {}
    for k, v in conf.items():
        conf_dict.update({k: {k: v for k, v in v.items()}})
    return conf_dict


if __name__ == '__main__':
    # conf_dict = {}
    # for k, v in conf.items():
    #     conf_dict.update({k: {k: v for k, v in v.items()}})
    print(get_config())
